/*宏定义和消息处理对象类型主题类型服务类型，和类型*/
#pragma once
#include<string>
#include<unordered_map>

namespace rpcType
{
    #define KEY_METHOD "method"
    #define KEY_PARAMS "parmeters"
    #define KEY_TOPIC_KEY "topic_key"
    #define KEY_TOPIC_MSG "topic_msg"//主题消息
    #define KEY_OPTYPE      "optype"
    #define KEY_HOST        "host"
    #define KEY_HOST_IP     "ip"
    #define KEY_HOST_PORT   "port"
    #define KEY_RCODE       "rcode"
    #define KEY_RESULT      "result"
    
    //类型
    enum class MType
    {
        //rpc请求&响应
        REQ_RPC = 0,
        RSP_RPC,
        //主题请求&响应
        REQ_TOPIC,
        RSP_TOPIC,
        //服务请求&响应
        REQ_SERVICE,
        RSP_SERVICE
    };

    //rpc编码
    enum class RCode
    {
        RCODE_OK = 0,
        RCODE_PARSE_FAILED,
        RCODE_ERROR_MSGTYPE,
        RCODE_INVALID_MSG,
        RCODE_DISCONNECTED,
        RCODE_INVALID_PARAMS,
        RCODE_NOT_FOUND_SERVICE,
        RCODE_INVALID_OPTYPE,
        RCODE_NOT_FOUND_TOPIC,
        RCODE_INTERNAL_ERROR
    };
    static std::string errReason(RCode code)
    {
        static std::unordered_map<RCode,std::string >err_map={
            {RCode::RCODE_OK,"处理成功"},
            {RCode::RCODE_PARSE_FAILED,"消息解析失败"},
            {RCode::RCODE_ERROR_MSGTYPE,"消息类型错误"},
            {RCode::RCODE_INVALID_MSG,"无效消息"},
            {RCode::RCODE_DISCONNECTED,"连接断开"},
            {RCode::RCODE_INVALID_PARAMS,"无效的rpc参数"},
            {RCode::RCODE_NOT_FOUND_SERVICE,"没有找到对应的服务"},
            {RCode::RCODE_INVALID_OPTYPE,"无效的操作类型"},
            {RCode::RCODE_NOT_FOUND_TOPIC,"没有找到对应的主题"},
            {RCode::RCODE_INTERNAL_ERROR,"内部错误"}
        };
        auto it = err_map.find(code);
        if(it==err_map.end())
        {
            return "未知错误";
        }
        return it->second;
    }
    //rpc类型
    enum class RTpe
    {
        REQ_ASYNC = 0,
        REQ_CALLABACK
    };
   
    //主题类型
    enum class TopicOptype
    {
         TOPIC_CREATE = 0,
        TOPIC_REMOVE,
        TOPIC_SUBSCRIBE,
        TOPIC_CANCEL,
        TOPIC_PUBLISH
    };
    enum class ServiceOptype
    {
         SERVICE_REGISTRY = 0,
        SERVICE_DISCOVERY,
        SERVICE_ONLINE,
        SERVICE_OFFLINE,
        SERVICE_UNKNOW
    };

} // namespace rpcType
